import productOrder from '@/components/product-item/components/product-order.vue'
import { detailOrder } from '@/api/order.js';
import { formatDate } from '@/utils/date';

export default {
	components: {
		productOrder
	},
	data() {
		return {
			orderSn: null,
			orderStatus: {},
			order: {},
			orderItemEntityList: [],
		};
	},
	onLoad(options) {
		this.orderSn = options.orderSn;
		this.loadData();
	},
	filters: {
		formatDateTime(time) {
			if (time == null || time === '') {
				return 'N/A';
			}
			let date = new Date(time);
			return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
		},
		formatPayType(payType) {
			if (payType == 0) {
				return "未支付";
			} else if (payType == 1) {
				return "微信支付";
			} else if (payType == 2) {
				return "支付宝支付";
			} else if (payType == 3) {
				return "其他";
			}
			return "未支付";
		},
	},
	methods: {
		//生成确认单信息
		async loadData() {
			let params = {
				orderSn: this.orderSn
			}
			detailOrder(params).then(response => {
				this.order = response.data;
				this.orderItemEntityList = this.order.orderItemEntityList;
				this.setOrderStatus(this.order.status);
				
			});
		},
		//设置订单状态信息
		setOrderStatus(status) {
			switch (status) {
				case 0:
					this.orderStatus = {
						text: '等待付款',
						icon: 'icon-daifukuan1',
						color: '#FF00BF'
					}
					break;
				case 1:
					this.orderStatus = {
						text: '交易完成',
						icon: 'icon-xuanzhong',
						color: '#0000FF'
					}
					break;
				case 2:
					this.orderStatus = {
						text: '交易关闭',
						icon: 'icon-icon--shanchu',
						color: '#DF013A'
					}
					break;
			};
		},
		//详情
		navToDetailPage(item) {
			uni.navigateTo({
				url: `/pages/product/product?sku=${item.sku}`
			})
		},
	}
}